package com.oscar.ehome.view.setview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.messageBean.MessageListBean;
import com.oscar.ehome.bean.pagebean.StudyListBean;
import com.oscar.ehome.utils.dowload.progressbar.RoundProgressBar;
import com.oscar.ehome.utils.util.DateUtil;
import com.oscar.ehome.view.messageview.adapter.MessageListAdapter;
import com.oscar.ehome.view.pageview.adapter.DownloadAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/21
 * 我的发布页
 */

public class MyIssuesAdapter extends BaseAdapter {

    private List<MessageListBean> list;
    private LayoutInflater mInflater;
    private Context mContext = null;

    public MyIssuesAdapter(Context context, List<MessageListBean> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<MessageListBean> specailList) {
        this.list = specailList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_mymessage, null);
            holder = new ViewHolder();
            holder.mymessage_title = (TextView) convertView.findViewById(R.id.mymessage_title);
            holder.mymessage_time = (TextView) convertView.findViewById(R.id.mymessage_time);
            holder.mymessage_img = (ImageView) convertView.findViewById(R.id.mymessage_img);
            holder.mymessage_titles = (TextView) convertView.findViewById(R.id.mymessage_titles);
            holder.mymessage_title_layout = (RelativeLayout) convertView.findViewById(R.id.mymessage_title_layout);

            holder.mymessage_title_layouts = (RelativeLayout) convertView.findViewById(R.id.mymessage_title_layouts);
            holder.mymessage_title_text = (TextView) convertView.findViewById(R.id.mymessage_title_text);
            holder.mymessage_time_text = (TextView) convertView.findViewById(R.id.mymessage_time_text);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (list.size() >= 0 || list != null) {
            MessageListBean listBean = list.get(position);
            String type = listBean.getType();
            String title = listBean.getTitle();
            String isSticky = listBean.getIsSticky();
            switch (type) {
                case "1"://通知
                    holder.mymessage_img.setBackgroundResource(R.mipmap.tongzhi1);
                    if ("1".equals(isSticky)) {
                        holder.mymessage_titles.setText(R.string.message_inform);
                    } else {
                        holder.mymessage_title_text.setText(R.string.message_inform);
                    }
                    break;
                case "2"://激励
                    holder.mymessage_img.setBackgroundResource(R.mipmap.jili1);
                    if ("1".equals(isSticky)) {
                        holder.mymessage_titles.setText(R.string.message_exciting);
                    } else {
                        holder.mymessage_title_text.setText(R.string.message_exciting);
                    }
                    break;
                case "3"://产品
                    holder.mymessage_img.setBackgroundResource(R.mipmap.chanpin1);
                    if ("1".equals(isSticky)) {
                        holder.mymessage_titles.setText(R.string.message_product);
                    } else {
                        holder.mymessage_title_text.setText(R.string.message_product);
                    }
                    break;
                case "4"://会议
                    holder.mymessage_img.setBackgroundResource(R.mipmap.huiyi1);
                    if ("1".equals(isSticky)) {
                        holder.mymessage_titles.setText(R.string.message_meeting);
                    } else {
                        holder.mymessage_title_text.setText(R.string.message_meeting);
                    }
                    break;
                case "5"://系统
                    holder.mymessage_img.setBackgroundResource(R.mipmap.xitong1);
                    if ("1".equals(isSticky)) {
                        holder.mymessage_titles.setText(R.string.message_system);
                    } else {
                        holder.mymessage_title_text.setText(R.string.message_system);
                    }
                    break;
            }

            String date = DateUtil.timeLogic(listBean.getUpdateDate());
            holder.mymessage_title.setText(title);

            if ("1".equals(isSticky)) {//有置顶时
                holder.mymessage_title_layout.setVisibility(View.VISIBLE);
                holder.mymessage_title_layouts.setVisibility(View.GONE);
                holder.mymessage_time.setText(date);
            } else {//无置顶时
                holder.mymessage_title_layout.setVisibility(View.GONE);
                holder.mymessage_title_layouts.setVisibility(View.VISIBLE);
                holder.mymessage_time_text.setText(date);
            }
        }


        return convertView;
    }


    class ViewHolder {
        TextView mymessage_time;
        TextView mymessage_title;
        ImageView mymessage_img;
        TextView mymessage_titles;
        RelativeLayout mymessage_title_layout;//有置顶的布局

        RelativeLayout mymessage_title_layouts;//无置顶的布局
        TextView mymessage_title_text;
        TextView mymessage_time_text;
    }

}
